package org.jrfe.res;

import org.jrfe.res.impl.OpenALSoundManagerImpl;
import org.jrfe.res.impl.TextureManagerImpl;

public abstract class JRFEResource {

	private static TextureManager texManager;
	private static SoundManager sndManager;
		
	@SuppressWarnings("unchecked")
	public void createSoundManager(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		if(cls == null){
			sndManager = new OpenALSoundManagerImpl();
		}else{
			Class c = Class.forName(cls);
			sndManager = (SoundManager)c.newInstance();
		}
	}
	
	public static boolean initilizeSoundManager(Object... obs){
		if(sndManager == null){
			sndManager = new OpenALSoundManagerImpl();
		}
		if(!sndManager.isInitialized()){
			return sndManager.initilizeManager(obs);
		}else{
			return true;
		}
	}
	
	@SuppressWarnings("unchecked")
	public void createTextureManager(String cls) throws InstantiationException, IllegalAccessException, ClassNotFoundException{
		if(cls == null){
			texManager = new TextureManagerImpl();
		}else{
			Class c = Class.forName(cls);
			texManager = (TextureManager)c.newInstance();
		}
	}
	
	public static boolean initilizeTextureManager(Object... obs){
		if(texManager == null){
			texManager = new TextureManagerImpl();
		}
		if(!texManager.isInitialized()){
			return texManager.initilizeManager(obs);
		}else{
			return true;
		}
	}
	
	public static void destroySoundManager(){
		if(sndManager != null && sndManager.isInitialized()){
			sndManager.destoryManager();
		}
	}
	
	public static void destroyTextureManager(){
		if(texManager  != null && texManager.isInitialized()){
			texManager.destoryManager();
		}
	}	
	
	public static TextureManager getTexManager() {
		return texManager;
	}
	
	public static SoundManager getSndManager() {
		return sndManager;
	}
	
}
